﻿#ifndef QFILESTORAGECLIENT_H
#define QFILESTORAGECLIENT_H

#include <QObject>

struct RemoteFileInfo
{
    bool isDir;
    int state; //0:成功；-1：路径为空；-2：路径不存在；
    uint64_t fileSize;
    RemoteFileInfo()
    {
        isDir = true;
        state = -3; //0:成功；-1：路径为空；-2：路径不存在；
        fileSize = 0;
    }
};

class QFileStorageClient : public QObject
{
    Q_OBJECT
public:
    explicit QFileStorageClient(QObject *parent = nullptr);
    ~QFileStorageClient();

public:
    void setServiceAddress(QString url);

    bool pushFile(const QString &localPath, const QString &remotePath);
    bool pullFile(const QString &localPath, const QString &remotePath);
    bool pushData(const QByteArray &localData, const QString &remotePath);
    bool pullData(QByteArray &localData, const QString &remotePath);
    bool getFileInfo(const QString &remotePath, RemoteFileInfo &info);

    QString getLastErrorText() const;
    int getLastErrorCode() const;

private:
    QString serviceAddress;
    int lastErrorCode;
    QString lastErrorText;
};

#endif // QFILESTORAGECLIENT_H
